<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>库存</title>
    <% include("../layout/css.html"){} %>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card card-box-shadow">
    	<div class="layui-card-body">
	        <div class="layui-form toolbar">
	            <div class="layui-form-item">
	                <div class="layui-inline">
	                    <label class="layui-form-label w-auto">搜索：</label>
	                    <div class="layui-input-inline mr0">
	                        <input name="warehouseName" class="layui-input" type="text" placeholder="仓库,产品,规格"/>
	                    </div>
	                </div>
	                <div class="layui-inline">
	                    <button class="layui-btn icon-btn" lay-filter="searchSubmit" type="button" lay-submit>
	                        <i class="layui-icon">&#xe615;</i>搜索
	                    </button>
	                </div>
	            </div>
	        </div>
        	<table class="layui-table" id="productStorageTable" lay-filter="productStorageTable"></table>
			<div class="layui-form layui-form-item text-right">
				<button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
				<button class="layui-btn" lay-filter="modelProductStorageSelSubmit" lay-submit>保存</button>
			</div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container layui-hide" >
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData" id="getCheckData">获取选中行数据</button>
    </div>
</script>
<!-- js部分 -->
<% include("../layout/js.html"){} %>
<script type="text/javascript">
    layui.use(['layer', 'form', 'formX', 'table', 'util', 'admin', 'zTree', 'tableX','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var tableX = layui.tableX;
        var laydate = layui.laydate;
        var formX = layui.formX;

        // 渲染表格
        var insTb = tableX.render({
            elem: '#productStorageTable'
            ,url: 'list'
            ,page: true
            ,toolbar: '#toolbarDemo'
            ,cellMinWidth: 100
            ,cols: [[
                {type: 'numbers'}
                ,{type: 'radio'}
                ,{field: "warehouseName", minWidth: "60", title: "仓库名称", sort: true, hide:false }
                ,{field: "productName", minWidth: "60", title: "产品名称", sort: true, hide:false }
                ,{field: "specification", minWidth: "60", title: "规格", sort: true, hide:false }
                ,{field: "lengths", minWidth: "60", title: "长度", sort: true, hide:false }
                ,{field: "negative", minWidth: "60", title: "负差", sort: true, hide:false }
                ,{field: "num", minWidth: "60", title: "数量", sort: true, hide:false }
                ,{field: "liWeight", minWidth: "60", title: "理论质量", sort: false, hide:false }
                ,{field: "liTotalWeight", minWidth: "60", title: "理算总重量", sort: true, hide:false }
                ,{field: "price", minWidth: "60", title: "价格", sort: true, hide:true }
                ,{field: "model", minWidth: "60", title: "材质", sort: true, hide:true }
                ,{field: "locality", minWidth: "60", title: "产地", sort: true, hide:true }
                ,{field: "remark", minWidth: "60", title: "备注", sort: true, hide:true }
                ,{field: "orderNum", minWidth: "60", title: "排序", sort: true, hide:true }
                ,{field: "createTime", minWidth: "60", title: "创建时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "createUser", minWidth: "60", title: "创建人", sort: true, hide:true }
                ,{field: "updateTime", minWidth: "60", title: "更新时间", sort: true, hide:true ,templet: function (d) {
                        return util.toDateString(d.createTime);
                    }
                }
                ,{field: "updateUser", minWidth: "60", title: "更新人", sort: true, hide:true }
            ]]
			,done: function(res, page, count){
				//可以自行添加判断的条件是否选中
				//这句才是真正选中，通过设置关键字LAY_CHECKED为true选中，这里只对第一行选中
//                res.data[0]["LAY_CHECKED"]='true';
				//下面三句是通过更改css来实现选中的效果
				$.each(res.data, function(k,v){
					if(v.id=="${productStorage.id}" || (v.name=="${productStorage.warehouseName}"
							&& v.name=="${productStorage.productName}"&& v.name=="${productStorage.specification}"
							&& v.name=="${productStorage.lengths}")){
						$('tr[data-index=' + k + '] input[type="radio"]').parent().find("i").click();
//                        $('tr[data-index=' + k + '] input[type="radio"]').prop('checked', true);
//                        $('tr[data-index=' + k + '] input[type="radio"]').next().addClass('layui-form-checked');
					}
				})
			}
        });

		//监听行单击事件（单击事件为：rowDouble）
		table.on('row(productStorageTable)', function(obj){
			// console.log(obj.tr.attr("data-index"))
			//选中行样式
			obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
			//选中radio样式
			obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
			// $('tr[data-index=' + obj.tr.attr("data-index") + '] input[type="radio"]').parent().find("i").click();
			/* obj.tr.find('input[type="radio"]').prop('checked', true);
             form.render('radio');*/
			/*var data = obj.data;

            layer.alert(JSON.stringify(data), {
                title: '当前行数据：'
            });

            //标注选中样式
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');*/
//            $(obj.tr[0].outerHTML).attr("data-index")
		});

		// 搜索
		form.on('submit(searchSubmit)', function (data) {
			insTb.reload({where: data.field, page: {curr: 1}});
		});
		// 搜索
		form.on('submit(modelProductStorageSelSubmit)', function (data) {
			$("#getCheckData").click();
		});

		//头工具栏事件
		table.on('toolbar(productStorageTable)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
			switch(obj.event){
				case 'getCheckData':
					getCheckData(obj,checkStatus);
					break;
			};
		});
		function getCheckData(obj,checkStatus){
			var data = checkStatus.data;  //获取选中行数据
			//layer.alert(JSON.stringify(data));
			if(data.length>0){
				top.productStorageSel(data);
				admin.closeThisDialog();
			} else {
				layer.alert("请选择库存!");
			}
		}
    });
</script>
</body>
</html>
